package com.ruoyi.web.controller.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.base.domain.BusWaterIndustry;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BasPollutionsource;
import com.ruoyi.base.service.IBasPollutionsourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工业污染源Controller
 * 
 * @author maliang
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/base/pollutionsource")
public class BasPollutionsourceController extends BaseController
{
    @Autowired
    private IBasPollutionsourceService basPollutionsourceService;

    /**
     * 查询工业污染源列表
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasPollutionsource basPollutionsource)
    {
        startPage();
        List<BasPollutionsource> list = basPollutionsourceService.selectBasPollutionsourceList(basPollutionsource);
        return getDataTable(list);
    }

    @GetMapping("/listall")
    public AjaxResult listall()
    {
        List<BasPollutionsource> list = basPollutionsourceService.selectBasPollutionsourceList(new BasPollutionsource());
        List<Map> mapList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (BasPollutionsource pollutionsource : list) {
                Map map = new HashMap();
                map.put("polluteid",pollutionsource.getId());
                map.put("pollutename",pollutionsource.getPollutename());
                mapList.add(map);
            }
        }
        return AjaxResult.success(mapList);
    }

    @GetMapping("/treelist")
    public AjaxResult treelist()
    {
        List<Map> list = basPollutionsourceService.treelist();
        return AjaxResult.success(list);
    }

    /**
     * 导出工业污染源列表
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:export')")
//    @Log(title = "工业污染源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasPollutionsource basPollutionsource)
    {
        List<BasPollutionsource> list = basPollutionsourceService.selectBasPollutionsourceList(basPollutionsource);
        ExcelUtil<BasPollutionsource> util = new ExcelUtil<BasPollutionsource>(BasPollutionsource.class);
        util.exportExcel(response, list, "污染源数据");
    }

    /**
     * 获取工业污染源详细信息
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(basPollutionsourceService.selectBasPollutionsourceById(id));
    }

    /**
     * 新增工业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:add')")
//    @Log(title = "工业污染源", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BasPollutionsource basPollutionsource)
    {
        return toAjax(basPollutionsourceService.insertBasPollutionsource(basPollutionsource));
    }

    /**
     * 修改工业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:edit')")
//    @Log(title = "工业污染源", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BasPollutionsource basPollutionsource)
    {
        return toAjax(basPollutionsourceService.updateBasPollutionsource(basPollutionsource));
    }

    /**
     * 删除工业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:pollutionsource:remove')")
//    @Log(title = "工业污染源", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(basPollutionsourceService.deleteBasPollutionsourceByIds(ids));
    }


    /**
     * 行业类型
     */
    @GetMapping("/industryList")
    public TableDataInfo list(BusWaterIndustry busWaterIndustry)
    {
        startPage();
        List<BusWaterIndustry> list = basPollutionsourceService.selectBusWaterIndustryList(busWaterIndustry);
        return getDataTable(list);
    }


}
